import java.util.Stack;

public class Text {
    public static boolean IsPopOrder(int [] pushA,int [] popA) {
        Stack<Integer> stack = new Stack<>();
        int j=0;
        for(int i=0; i<pushA.length;i++){
            stack.push(pushA[i]);
            while(j<popA.length && !stack.empty() && stack.peek() == popA[j]){
                stack.pop();
                j++;
            }
        }
        return stack.empty();
    }
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(int i=0; i<tokens.length;i++){
            String val = tokens[i];
            if(isOpretation(val)){
                int nums1 = stack.pop();
                int nums2 = stack.pop();
                switch(val){
                    case "+":
                        stack.push(nums2+nums1);
                        break;
                    case "-":
                        stack.push(nums2-nums1);
                        break;
                    case "*":
                        stack.push(nums2*nums1);
                        break;
                    case "/":
                        stack.push(nums2/nums1);
                        break;
                }
            }else{
                stack.push(Integer.parseInt(val));
            }
        }
        return stack.pop();
    }
    private boolean isOpretation(String val){
        if(val.equals("+")||val.equals("-")||val.equals("*")||val.equals("/")){
            return true;
        }else{
            return false;
        }
    }
}
